Open
Conversation
d3lm
requested changes
Sep 19, 2022
Comment on lines
+15
to
+19
| export enum TicketStatus { | ||
| CLOSED: 'closed', | ||
| OPEN: 'open', | ||
| WAITING_RESPONSE: 'waiting response', | ||
| } |
Member
There was a problem hiding this comment.
A bit of a personal preference but for enums I do the following:
Suggested change
| export enum TicketStatus { | |
| CLOSED: 'closed', | |
| OPEN: 'open', | |
| WAITING_RESPONSE: 'waiting response', | |
| } | |
| export enum TicketStatus { | |
| Closed = 'Closed', | |
| Open = 'Open', | |
| WaitingResponse = 'WaitingResponse', | |
| } |
Member
There was a problem hiding this comment.
I would also mention to use const enum where possible.
| @@ -0,0 +1,47 @@ | |||
| --- | |||
| title: define enums for variables with already known multiple possible values | |||
Member
There was a problem hiding this comment.
Can we find a slightly shorter title? Maybe
use enums for named constants
|
|
||
| # Problem | ||
|
|
||
| When we're working with variables, sometimes you'd need to have variables with already known multiple possible values, that will always be the same in your application (think about having a ticket status variable, `CLOSED`, `OPEN`, `WAITING RESPONSE`) |
|
|
||
| # Solution | ||
|
|
||
| Typescript allows us to define enumerators, which are variables with multiple defined possible values. By using enumerables TS will be able to infer and autocomplete the possible values of a variable inside your code. |
Member
There was a problem hiding this comment.
enumerators -> enums
TS -> TypeScript
autocomplete the possible values -> autocomplete possible values
|
|
||
| Typescript allows us to define enumerators, which are variables with multiple defined possible values. By using enumerables TS will be able to infer and autocomplete the possible values of a variable inside your code. | ||
|
|
||
| We can create different enumerables as follows: |
| } | ||
| ``` | ||
|
|
||
| We can assign any value to our enumerable properties, in this previous example, if you had numeric values for your variable then it'd look like this: |
Member
There was a problem hiding this comment.
This sentence is a little hard to read. We should break it up a little.
| } | ||
| ``` | ||
|
|
||
| So when you or someone else is working later on the code they can use the enum like this: |
| // do something | ||
| } | ||
| ``` | ||
| or |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a new topic about using
enumsin typescript.